
class JQRefreshService extends global.JQService {
    async do_action(){
		
		console.log('reresh 1111');
		let data_obj = global.JQRequest.parseFromData(this.req_obj.data);
		let session_table = global.JQTableIF.instance('login_session_table',this.conn);
		if(!session_table)return null;
			console.log('login session 22222');
		let session_obj = await session_table.queryOne(null,
			['session_token=',this.req_obj.session_token]);              
		// appid, secret, code,isMA
		let buyer_table = global.JQTableIF.instance('buyer_table',this.conn);
		console.log('buyer table name');
		let buyer_obj = await buyer_table.get(session_obj.visitor_id);
		console.log('buyer obj ' +JSON.stringify(buyer_obj));
		if(!buyer_obj){
			return null;
		}	
		
		if(!session_obj){
			return null;
		}else{
			session_obj.visitor_id = buyer_obj.b_id;
			session_obj.uid=this.req_obj.u_id;
			let phone =buyer_obj.bound_phone;//buyer_obj.bound_phone
			if(phone){
				let account_table = global.JQTableIF.instance('account_table',this.conn);
			
				let account = await account_table.queryOne(['id'], ['username=',phone]);
				if(account){
					let employee_table =  global.JQTableIF.instance('employee_table',this.conn);
					let employee_obj = await employee_table.queryOne(['id'],
						[['uid=',this.req_obj.u_id],['aid=',account.id]]);
					if(employee_obj){
						session_obj.eid= employee_obj.id;
						if(!data_obj.role || data_obj.role != 'visitor'){
							session_obj.role='admin';
						}else{
							session_obj.role='visitor';
						}
						
						session_obj.roles='admin;visitor';
					}else{
						session_obj.role='visitor';
						session_obj.roles='visitor';
					}
				}
				
			}else{
				session_obj.role='visitor';
				session_obj.roles='visitor';
			}
			
		}
		if(buyer_obj.b_member_id)session_obj.member_id= buyer_obj.b_member_id;
		session_obj = session_table.create(session_obj);
		return session_obj;			
	}

}
module.exports = JQRefreshService;

